// Copyright (C) joyinter
// All rights reserved.
// 
// Author : Jiang Li
// Date   : 2005-4-30

#ifndef __CSUMPEIMAGE_H_COMMON_GUARD__
#define __CSUMPEIMAGE_H_COMMON_GUARD__

#pragma once

#include "csumpefile.h"

namespace JoyGuard
{

//##ModelId=44C4B60E0030
class CSumPeImage
{
public:
	//##ModelId=44C4B60E009E
    enum ErrorCode
    {
		//##ModelId=44C4B60E00A0
        EC_OK,
		//##ModelId=44C4B60E00AB
        EC_FAILED,
		//##ModelId=44C4B60E00AC
        EC_READ_MEMORY,
		//##ModelId=44C4B60E00AD
        EC_CHECK_SUM,
    };
	//##ModelId=44C4B60E00BB
    class ECheckStop : public std::exception
    {
    };

	//##ModelId=44C4B60E003E
    volatile bool    m_stopped;
	//##ModelId=44C4B60E003F
    DWORD   m_error;
	//##ModelId=44C4B60E0040
    HANDLE  m_process;
	//##ModelId=44C4B60E004E
    BYTE*   m_baseAddr;
	//##ModelId=44C4B60E0050
    std::vector<BYTE>   m_tempBase;
	//##ModelId=44C4B60E005D
    DWORD   m_readSize;
	//##ModelId=44C4B60E005E
    DWORD   m_readDelay;
	//##ModelId=44C4B60E005F
    DWORD   m_readed;
	//##ModelId=44C4B60E0061
    CSumSect    m_csumSect;
	//##ModelId=44C4B60E006D
    HANDLE  m_waitEvent;
	//##ModelId=44C4B60E006F
    IMAGE_NT_HEADERS* m_ntHeaders;

	//##ModelId=44C4B60E0073
    void CheckStop();
	//##ModelId=44C4B60E007D
    void ReadMemory(BYTE* dst, BYTE* src, int len);
public:
	//##ModelId=44C4B60E0081
    CSumPeImage();

	//##ModelId=44C4B60E0082
    bool Create(HANDLE waitEvent, HANDLE hProcess, BYTE* baseAddr, const CSumSect& ss, DWORD readSize = 0, DWORD readDelay = 0);
	//##ModelId=44C4B60E009C
    void Close();
	//##ModelId=44C4B60E009D
    bool Check();
};

} // namespace JoyGuard

#endif  // __CSUMPEIMAGE_H_COMMON_GUARD__
